package com.hdu.service.impl;


import com.hdu.dao.URLDAO;
import com.hdu.pojo.VisitedUrl;
import com.hdu.service.URLService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

import static com.hdu.util.RedisConstants.Visit_Count_Key;

@Service
public class URLServiceImpl implements URLService {

    @Autowired
    URLDAO urlDao;

    @Autowired
    StringRedisTemplate stringRedisTemplate;

    @Override
    public VisitedUrl getVisitedUrlById(Long id) {
        return urlDao.getVisitedUrlById(id);
    }

    @Override
    public boolean addVisitedUrl(VisitedUrl visitedUrl) {
        return urlDao.addVisitedUrl(visitedUrl);
    }

    @Override
    public boolean updateVisitedUrl(VisitedUrl visitedUrl) {
        return urlDao.updateVisitedUrl(visitedUrl);
    }

    @Override
    public boolean deleteVisitedUrl(Long id) {
        return urlDao.deleteVisitedUrl(id);
    }

    @Override
    public Integer getVisitedUrlCountsByUrl(String url) {
        return urlDao.getVisitedUrlCountsByUrl(url);
    }

    @Override
    public boolean incrementVisitedCount(String url) {
        stringRedisTemplate.opsForValue().increment(Visit_Count_Key + url);
        return true;
    }
}
